package com.platform.controller.backend;

import com.platform.common.ServerResponse;
import com.platform.pojo.RolePermission;
import com.platform.service.IRolePermissionService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 角色操作权限
 */
@Controller
@RequestMapping("/rolePermissionController/")
public class RolePermissionController {

    @Autowired
    private IRolePermissionService iRolePermissionService;

    @RequestMapping(value = "add.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> addRolePermission(Map param){
        return iRolePermissionService.insert(param);
    }

    @RequestMapping(value = "del.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> del(Integer id){
       return iRolePermissionService.del(id);
    }

    @RequestMapping(value = "selectByParam.do",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse<List<Integer>> selectByParam(String roleCode){
        return iRolePermissionService.selectByParam(roleCode);
    }

    @RequestMapping(value = "update.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> update(RolePermission rolePermission){
        return iRolePermissionService.update(rolePermission);
    }

    @RequestMapping(value = "selectAllPermission.do",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse<List<Map>> selectAllPermission(String roleCode){
        return iRolePermissionService.selectAllPermission(roleCode);
    }


    @RequestMapping(value = "addRolePermission.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> addRolePermission(@RequestParam(value = "roleCode") String roleCode,
                                                    @RequestParam(value = "perIdArr") String perIdArr){
        return iRolePermissionService.addRolePermission(roleCode,perIdArr);
    }
}
